<?php 

/********* Dreamscape ***********/
require('funcs/admin.php');
if(LOGGED_IN){
if((ADDING || EDITING) && !empty($catid)){
		$cats = $sections->GetList(array(array('id', '=', $catid),array('pid', '=', 0)));
		$more_cats = $sections->GetList(array(array('pid', '=', 0)));
		foreach($more_cats as $k => $v){
			if(!in_array($v->id, $auth->Permissions) || ($v->id == $catid)){
				unset($more_cats[$k]);
			}
		}
		$cat_type = !empty($cats) ? $cats[0]->cat_type : NULL;
		$category_clean_name = !empty($cats) ? $cats[0]->dirtitle : '';
		define('CLEAN_CAT_NAME', $category_clean_name);
		$cats = getCatList($catid);
		if(file_exists("$modules_dir/$cat_type/controller.php") 
		&& file_exists("$modules_dir/$cat_type/view.php") 
		&& !is_null($cat_type)){
			$module_exists = true;
			$module_css = file_exists("$modules_dir/$cat_type/styles.css") ? DREAMSCAPE_URL.'modules/'.$cat_type.'/styles.css' : '';
			$module_js = file_exists("$modules_dir/$cat_type/javascript.js") ? DREAMSCAPE_URL.'modules/'.$cat_type.'/javascript.js' : '';
			include("$modules_dir/$cat_type/controller.php");
			$the_module = (class_exists($cat_type)) ? new $cat_type : new Module;
			$errors =& $the_module->errors;
			$the_module->more();
			if(ADDING){
				/*   ADDING   //-------------------------------*/
				if(is_posting(L_BUTTON_ADD)){
					$the_module->add();
				}
			} else {
				/*   EDITING   //-------------------------------*/
				if(EDIT_SINGLE){
					if(is_posting(L_BUTTON_EDIT)){
						$the_module->edit();
						}
						$items = $the_module->get_single();	
					} elseif(EDIT_LIST) {
						if(is_posting(L_BUTTON_DELETE)){
						$the_module->delete();
						}
						$itemsList = $the_module->get_list();
					}
				}
			$the_module->add_title();
			}
} // end adding or editing
}
$wordwrap = 75;
$descrlength = 80;
/*   Header   //-------------------------------*/
$outmess->write_header($pagetitle);
?>
 

  <?php 
  if(LOGGED_IN){
  ?>
  <div id="menu">
<?php echo $menu; ?></div>
  <div id="content"<?php echo empty($the_type) ? ' class="mainPage"' : ''; ?>>
  <form method="post" action="" enctype="multipart/form-data" id="post" name="post">
  <?php 
  if(!(empty($catid) && empty($cat))){
  ?>
  <div id="contentHead" class="breadcrumb"><?php echo $outmess->generateBreadCrumbs($catid, 'edit');?></div>
  <?php
  } 
  echo $output;
  if(ADDING && !empty($catid)){
  	include('add.php');
  } elseif(EDITING && !empty($catid)){
  	include('edit.php');
  }  elseif (CAT == 'admin' && $auth->Admin){ 
	  		if (empty($admin_sub)){
	  ?> 
<?php echo $output; ?>
<ul id="catList" class="adminList">
<?php 
applyOzoneAction('admin_menu_list', $admin_menu['details']);
foreach($admin_menu['details'] as $menu_item){
?>
<li id="<?php echo $menu_item['id']; ?>"><h1><?php echo $menu_item['title']; ?></h1> 
  <?php echo $menu_item['links']; ?>
  <p><?php echo $menu_item['description']; ?></p>
  </li>
<?php
}
applyOzoneAction('admin_menu');
?>

</ul>
        <?php
}

elseif (!empty($admin_sub)){
		applyOzoneAction('admin_page');
}
	  }elseif(is_home()){
  		include('main.php');
  }	elseif(CAT == 'upgrade'){
	include('upgrade.php');
	}else { ?>
<p><?php echo L_NOTHING_HERE ?></p>
<?php 
}
  

  } // /End if logged in
  else {
  ?>
    <div id="content" class="login">
  <h1><?php printf(L_MAIN_TITLE,CMS_NAME); ?></h1>
  <form method="post" action="" id="post" name="post">
   <?php 
   echo $output;
   if(isset($_GET['action']) && $_GET['action'] == 'forgot'){
   if(!isset($_GET['reset_key'])){
   ?>
   <label for="username"><?php echo L_LOGIN_USERNAME ?></label><input name="username" id="username" type="text" /><br />
   <label for="email"><?php echo L_LOGIN_EMAIL ?></label><input name="email" id="email" type="text" /><br />
   <label for="get_password"></label><input name="get_password" id="get_password" type="submit" class="buttons" value="<?php echo L_BUTTON_GET_INFO ?>" />
   <?php
   }  else {
   ?>
   <a href="./"><?php echo L_LOGIN_GO_BACK ?></a>
   <?php
   }
   } else {
   ?>
    <h2><?php echo L_GET_STARTED ?></h2>
		  <label for="username"><?php echo L_LOGIN_USERNAME ?></label>
		  <input name="username" type="text" id="username" value="<?php echo @$_POST['password'] ?>" /><br />
		  <label for="password"><?php echo L_LOGIN_PASSWORD ?></label>
		  <input name="password" type="password" id="password" /><br />
		  <label for="rememberme"><?php echo L_LOGIN_REMEMBER_ME ?></label>
		  <input name="rememberme" type="checkbox" id="rememberme" value="1" />
		  <br />
		  <label for="login"></label>
		  <input name="login" type="submit" id="login" value="Submit" />
		  <a href="index.php?action=forgot" title="<?php echo L_LOGIN_FORGOT_PASSWORD ?>" id="forgotLink">
		  <?php echo L_LOGIN_FORGOT_PASSWORD ?></a><br />
		  
<?php 					
   } //Not resetting
   ?>
  <?php
  } // /End not logged in
  ?>
   
  
	</form>
</div>
<?php $outmess->write_footer(); ?>
